Skip to content

Node.js and NPM

The most foundational tool you need, in order to start working on local React projects, is Node.js.

This surprises some people. Node.js is a server runtime, typically used to build back-end web servers / APIs. React is a front-end framework. Why on earth would we need Node??

Well, as we talked about in Module 1, React apps need to go through a compilation step, which transforms JSX into plain JavaScript. That process typically runs using Node.js.

As we'll learn, React developers rely on Node to help us out with all sorts of tasks. And so it's the very first thing we need to tackle.

Installing Node

Node.js offers installers for Windows, macOS, and Linux. Head on over to the Node.js Downloads page and pick your platform.

In terms of version, I recommend using the “LTS” version. LTS stands for “Long-Term Support”. You'll be getting the newest version that the team is committed to maintaining. You'll run into fewer issues this way, compared to getting the very latest “bleeding edge” version.

Checking Node version

You can check which version of Node you're currently using by running node --version (or node -v for short).

This is useful in a few cases:

  • You're wondering if you have Node installed or not (if you don't, you'll get an error)
  • You installed it a while ago, and you want to know if it's up-to-date
  • You use a version manager and aren't sure which one is “active”.

Running Node locally

Once you've installed Node, you can open a Node interpreter in the terminal by running:

node

This is similar to opening the “Console” in the developer tools. It's a place for you to quickly write and run some JavaScript.

This is useful for quickly testing out little ideas. I run node whenever I have some math to do; it's faster and easier than using a calculator application!

You can exit out of Node by pressing ctrl + D.